import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:wu_you/data/cache/language_cache.dart';
import 'package:wu_you/l10n/messages.dart';
import 'package:wu_you/res/colors.dart';
import 'package:wu_you/utils/utils.dart';
import 'package:wu_you/widgets/button_view.dart';
import 'package:qr_flutter/qr_flutter.dart';

class TeamCodeView extends StatefulWidget{
  final String url;
  TeamCodeView({Key key,this.url}):super(key: key);
  @override
  TeamCodeViewState createState() => TeamCodeViewState();
}
class TeamCodeViewState extends State<TeamCodeView>{
  var message;
  String language = "1";
  @override
  void initState() {
    super.initState();
    getLanguage();
  }

  getLanguage(){
    LanguageCache().get().then((v){
      language = v;
      setState(() {});
    });
  }
  @override
  Widget build(BuildContext context) {
    message = AppLocalizations.of(context);
    return Material(
      color: Colors.transparent,
      child: WillPopScope(
        child: Center(
          child: Padding(
              padding: EdgeInsets.only(left: 30, right: 30),
              child: Container(
                margin: EdgeInsets.only(bottom: 8),
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.all(Radius.circular(8)),
                    color: Colors.white
                ),
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Container(
                        margin: EdgeInsets.only(top: 20,left: 12,right: 12),
                        child:  Column(
                          mainAxisSize: MainAxisSize.min,
                          children: [
                            Text("${message['share7']}",style: TextStyle(color: AppColors.primaryColor,fontSize: 16,fontWeight: FontWeight.bold),),
                            SizedBox(height: 2,),
                            // Text("用户通过此二维码注册，分享归属为本账号。",style: TextStyle(color: AppColors.primaryColor,fontSize: 14,fontWeight: FontWeight.bold),),
                          ],
                        )
                    ),
                    Container(
                        padding: EdgeInsets.only(left: 12,right: 12,top: 12,bottom: 12),
                        child: QrImage(
                          data: "${language == "1" ? widget.url +"&language=zh" : widget.url + "&language=en"}",
                          size: 250,
                          version: QrVersions.auto,
                          backgroundColor: Colors.white,
                        )
                    ),
                    Padding(
                        padding: EdgeInsets.only(bottom: 15,left: 50,right: 50,top: 12),
                        child: ElevatedButtonWidget(
                          style: ButtonStyle(
                            backgroundColor: MaterialStateProperty.all(AppColors.primaryColor),
                            shape: MaterialStateProperty.all(
                                StadiumBorder(
                                    side: BorderSide(
                                      style: BorderStyle.solid,
                                      color: AppColors.primaryColor,
                                    )
                                )
                            ),
                          ),
                          child: Text("${message['product27']}",style: TextStyle(fontSize: 15,color: Colors.white),),
                          onPressed: (){
                            Navigator.pop(context);
                          },
                        )
                    ),
                  ],
                )
              )
          ),
        ),
        onWillPop: () async {
          return true;
        },
      ),
    );
  }
}